<template>
  <div>
    <el-container>
      <!-- 顶部导航栏 -->
      <div class="header-nav">
        <div class="topbar">
          <div class="nav-default">
            <nav>
              <router-link to="/order">推荐必去</router-link>
            </nav>
            <nav>
              <router-link to="/collect">提交景点</router-link>
            </nav>
            <nav>
              <router-link to="/collect">留言反馈</router-link>
            </nav>
            <nav>
              <router-link to="/collect">特价优惠</router-link>
            </nav>
            <nav>
              <router-link to="/order">我的订单</router-link>
            </nav>
            <nav>
              <router-link to="/collect">我的收藏</router-link>
            </nav>

            <nav v-if="!this.$store.getters.getUser">
              <el-button type="text" @click="login">登录</el-button>
              <span class="sep">|</span>
              <el-button type="text" @click="register = true">注册</el-button>
            </nav>

            <nav v-else>
              <router-link to="/order">个人中心</router-link>
              <el-popover placement="top" width="180" v-model="visible">
                <p>确定退出登录吗?</p>
                <div style="text-align: right; margin: 10px 0 0">
                  <el-button type="primary" size="mini" @click="logout"
                    >确定</el-button
                  >
                  <el-button size="mini" type="text" @click="visible = false"
                    >取消</el-button
                  >
                </div>
                <el-button type="text" slot="reference"> 退出</el-button>
              </el-popover>
            </nav>
            <nav :class="getNum > 0 ? 'shopCart-full' : 'shopCart'">
              <router-link to="/shoppingCart">
                <i class="el-icon-shopping-cart-full"></i> 出行日记
                <span class="num">({{ getNum }})</span>
              </router-link>
            </nav>
          </div>
        </div>
      </div>
      <!-- 顶部导航栏END -->
      <!-- 顶栏容器 -->
      <el-header>
        <div class="header-menu">
          <el-menu
            :default-active="activeIndex"
            mode="horizontal"
            active-text-color="#409eff"
            router
          >
            <div class="logo">
              <router-link to="/">
                <img
                  src="@/assets/imgs/logo.png"
                  alt
                  width="190px"
                  height="53px"
                />
              </router-link>
            </div>
            <el-menu-item index="/">首页</el-menu-item>
            <el-menu-item index="/goods">景点</el-menu-item>
            <el-menu-item index="/gl">攻略</el-menu-item>
            <el-menu-item index="/special">专题</el-menu-item>
            <el-menu-item index="/imtest">测试页面</el-menu-item>
            <div class="so">
              <el-input placeholder="请输入搜索内容" v-model="search">
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  @click="searchClick"
                ></el-button>
              </el-input>
            </div>
          </el-menu>
        </div>
      </el-header>
      <!-- 顶栏容器END -->

      <!-- 主要区域容器 -->
      <div class="middle-main">
        <el-main>
          <!-- <router-view></router-view> -->
          <Nuxt keep-alive />
        </el-main>
      </div>
      <!-- 底栏容器START -->
      <div class="footer-detial">
        <!-- <el-footer>
          <div class="footer">
            <div class="ng-promise-box">
              <div class="ng-promise">
                <p class="text">
                  <a class="icon1" href="javascript:;">飞猫旅行</a>
                  <a class="icon2" href="javascript:;">承德出行</a>
                  <a class="icon3" style="margin-right: 0" href="javascript:;"
                    >会员折扣</a
                  >
                </p>
              </div>
            </div>
            <div class="github">
              <a href="#" target="_blank">
                <div class="github-but"></div>
              </a>
            </div>
            <div class="mod_help">
              <p>
                <nuxt-link to="/">首页</nuxt-link>
                <span>|</span>
                <nuxt-link to="/goods">全部景点</nuxt-link>
                <span>|</span>
                <router-link to="/about">关于我们</router-link>
              </p>
              <p class="coty">飞猫承德旅行版权所有 &copy; 2022-2023</p>
            </div>
          </div>
        </el-footer> -->

        <div class="macwk-footer white border-top pc-model">
          <div class="container">
            <a href="/" class="logo"
              ><svg
                id="macwk-svg-logo"
                width="32"
                height="32"
                xmlns="http://www.w3.org/2000/svg"
                data-v-6dd0b122
              >
                <title data-v-6dd0b122>FlyCat</title>
                <defs data-v-6dd0b122>
                  <linearGradient
                    x1="50%"
                    y1="0%"
                    x2="50%"
                    y2="100%"
                    id="a"
                    data-v-6dd0b122
                  >
                    <stop
                      offset="0%"
                      class="stop-color-circle"
                      data-v-6dd0b122
                    ></stop>
                    <stop
                      offset="100%"
                      class="stop-color-circle"
                      data-v-6dd0b122
                    ></stop>
                  </linearGradient>
                  <linearGradient
                    x1="100%"
                    y1="86.198%"
                    x2="-14.813%"
                    y2="-4.357%"
                    id="b"
                    data-v-6dd0b122
                  >
                    <stop
                      offset="0%"
                      class="stop-color-default"
                      data-v-6dd0b122
                    ></stop>
                    <stop
                      offset="40.927%"
                      class="stop-color-default"
                      data-v-6dd0b122
                    ></stop>
                    <stop
                      offset="100%"
                      class="stop-color-default"
                      data-v-6dd0b122
                    ></stop>
                  </linearGradient>
                </defs>
                <g fill="none" fill-rule="evenodd" data-v-6dd0b122>
                  <path
                    d="M29.952 16c0-1.933-1.562-3.5-3.488-3.5a3.494 3.494 0 0 0-3.488 3.5c0 1.933 1.561 3.5 3.488 3.5a3.494 3.494 0 0 0 3.488-3.5"
                    fill="url(#a)"
                    data-v-6dd0b122
                  ></path>
                  <path
                    d="M25.865 25.9a13.932 13.932 0 0 1-6.377 3.66c-1.115.286-2.284.44-3.488.44a13.893 13.893 0 0 1-10.512-4.797A13.968 13.968 0 0 1 2.048 16c0-3.523 1.298-6.742 3.44-9.203A13.893 13.893 0 0 1 16 2c1.204 0 2.373.154 3.488.44a13.932 13.932 0 0 1 6.377 3.66l-4.933 4.95A6.942 6.942 0 0 0 16 9c-3.852 0-6.976 3.134-6.976 7l.002.18C9.122 19.964 12.208 23 16 23c1.926 0 3.67-.784 4.932-2.05l4.933 4.95z"
                    fill="url(#b)"
                    data-v-6dd0b122
                  ></path>
                  <path
                    d="M20.932 11.05A6.942 6.942 0 0 0 16 9c-3.852 0-6.976 3.134-6.976 7a13.98 13.98 0 0 1 4.087-9.9 13.932 13.932 0 0 1 6.377-3.66l1.444 8.61z"
                    fill="url(#c)"
                    data-v-6dd0b122
                  ></path>
                </g>
              </svg>
              <span class="ml-4">FlyCat</span></a
            >
            <div class="nav-dev">
              <a href="/" class="nav-link">首页</a>
              <a href="/about" class="nav-link">关于 </a
              ><a href="/contact" class="nav-link">联系 </a
              ><a href="/privacy" class="nav-link">隐私 </a
              ><a href="/version" class="nav-link">版本检测 </a
              ><a href="/changelogs" class="nav-link">更新日志 </a>
            </div>
            <div class="copyright">
              <p class="mb-0">
                <span class="mr-3"
                  ><a href="https://beian.miit.gov.cn/" target="_blank"
                    >冀ICP备19036164号</a
                  ></span
                >
                <span>FlyCat.com © 2022. All rights reserved.</span>
              </p>
            </div>
          </div>
        </div>
      </div>
      <!-- 底栏容器END -->
      <!-- 主要区域容器END -->
    </el-container>
  </div>
</template>

<script>
import { mapActions } from "vuex";
import { mapGetters } from "vuex";
export default {
  beforeUpdate() {
    this.activeIndex = this.$route.path;
    console.log("此时高亮activeIndex", activeIndex);
  },
  name: "Index",

  components: {},

  props: {},

  data() {
    return {
      activeIndex: "", // 头部导航栏选中的标签
      search: "", // 搜索条件
      register: false, // 是否显示注册组件
      visible: false, // 是否退出登录
      partTime: false, // 兼职
    };
  },
  mounted() {
    // 获取浏览器localStorage，判断用户是否已经登录
    if (localStorage.getItem("user")) {
      // 如果已经登录，设置vuex登录状态
      this.setUser(JSON.parse(localStorage.getItem("user")));
    }
    /* window.setTimeout(() => {
      this.$message({
        duration: 0,
        showClose: true,
        message: `
        <p>飞猫旅行</p>
        <p style="padding:10px 0">欢迎互关，谢谢！</p>
        <p><a href="#" target="_blank">飞猫旅行</a></p>`,
        dangerouslyUseHTMLString: true,
        type: "success"
      });
    }, 1000 * 60); */
  },
  computed: {
    ...mapGetters(["getUser", "getNum"]),
  },
  watch: {
    // 获取vuex的登录状态
    getUser: function (val) {
      if (val === "") {
        // 用户没有登录
        this.setShoppingCart([]);
      } else {
        // 用户已经登录,获取该用户的购物车信息
        this.$axios
          .post("/cat/usercardgood/getShoppingCart/" + val.pid)
          .then((res) => {
            if (res.data.code === 200) {
              // 001 为成功, 更新vuex购物车状态
              this.setShoppingCart(res.data.data.shoppingCartData);
            } else {
              // 提示失败信息
              this.notifyError(res.data.msg);
            }
          })
          .catch((err) => {
            return Promise.reject(err);
          });
      }
    },
  },
  methods: {
    ...mapActions(["setUser", "setShowLogin", "setShoppingCart"]),
    login() {
      console.log("点击登陆");
      // 点击登录按钮, 通过更改vuex的showLogin值显示登录组件
      this.setShowLogin(true);
    },
    partTimeClick() {
      this.partTime = true;
    },
    handleClose(done) {
      done();
    },
    // 退出登录
    logout() {
      this.visible = false;
      // 清空本地登录信息
      localStorage.setItem("user", "");
      // 清空vuex登录信息
      this.setUser("");
      this.notifySucceed("成功退出登录");
    },

    // 接收注册子组件传过来的数据
    isRegister(val) {
      console.log(val + " 是否显示注册 ");
      this.register = val;
    },
    // 点击搜索按钮
    searchClick() {
      if (this.search != "") {
        // 跳转到全部商品页面,并传递搜索条件
        this.$router.push({ path: "/goods", query: { search: this.search } });
        this.search = "";
      }
    },
  },
};
</script>
<style>
/* @import "../assets/css/mac.css"; */
/* 全局CSS */
* {
  padding: 0;
  margin: 0;
  border: 0;
  list-style: none;
}
#app .el-header {
  padding: 0;
}
#app .el-main {
  min-height: 300px;
  padding-left: 0px;
  padding-right: 0px;
}
/* 解决 padding 20  */
.el-main {
  padding-left: 0px;
  padding-right: 0px;
}
.el-footer {
  padding-left: 0px;
  padding-right: 0px;
}
#app .el-footer {
  padding: 0;
}
a,
a:hover {
  text-decoration: none;
}
/* 全局CSS END */

/* 顶部导航栏CSS */
.header-nav {
  width: 100%;
  /* height: 60px; */
}
.topbar {
  font-size: 12px;
  font-weight: 50;
  height: 40px;
  width: 100%;

  background-color: #000000;
}
/**right END */
/**left START */
.nav-default {
  background-color: #000000;
  float: left;
  /* width: 100%; */
  /* margin: auto 300px; */
  margin-left: 20%;
}
/**竖线 */
.topbar .nav-default .sep {
  color: #fcfcfc;
  /* font-size: 13px; */
  margin: 0 5px;
}
/**button样式 */
.topbar .nav-default nav .el-button {
  color: #ffffff;
  font-size: 12px;
}
/**button hover */
.topbar .nav-default .el-button:hover {
  color: rgb(69, 136, 236);
}
.topbar .nav-default .shopCart {
  width: 120px;
  background: #000000;
}
.topbar .nav-default .shopCart:hover {
  background: #000000;
}
.topbar .nav-default .shopCart:hover a {
  color: rgb(69, 136, 236);
}
.topbar .nav-default .shopCart-full {
  width: 120px;
  color: rgb(0, 0, 0);
}
/**购物车有物品 */
.topbar .nav-default .shopCart-full a {
  color: rgb(69, 136, 236);
}
/* .topbar .nav-left ul {
  float: left;
} */
.topbar .nav-default nav {
  float: left;
  height: 40px;
  color: #ffffff;
  /* font-size: 13px; */
  text-align: center;
  line-height: 40px;
  margin-right: 30px;
}
.topbar .nav-default .sep {
  color: #ffffff;
  font-size: 13px;
  margin: 0 5px;
}
.topbar .nav-default nav a {
  color: #ffffff;
}
.topbar .nav-default a:hover {
  color: rgb(69, 136, 236);
}
/**left END */
/* 顶部导航栏CSS END */
/* 顶栏容器CSS */
.header-menu {
  width: 100%;
  height: 50px;
  z-index: 1000;
}
.el-header {
  margin-top: 20px;
}
.el-header .el-menu {
  max-width: 100%;
  margin: auto 150px;
}
/**LOGO */
.el-header .logo {
  height: 60px;
  width: 150px;
  float: left;
}
/**搜索框 */
.el-header .so {
  margin-top: 10px;
  width: 300px;
  margin-right: 20px;
  float: right;
  border-radius: 10px;
}
/* 顶栏容器CSS END */
.middle-main {
  width: 100%;
  /* height: 500px; */
}
/* 底栏容器CSS */
.footer-detial {
  width: 100%;
  /* height: 500px; */
}
/* 底栏容器CSS END */
.macwk-footer {
  width: 100%;
  border-top: 1px solid hsla(0, 0%, 0%, 0.09);
  height: 76px;
}
.macwk-footer .logo {
  display: flex;
  align-items: center;
}
.macwk-footer .logo img {
  width: 32px;
  margin-right: 100px;
}
.macwk-footer .logo span {
  font-size: 24px;
  font-weight: 700;
  flex-grow: 1;
  color: #000000;
}
.macwk-footer > .container-xxl {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  height: inherit;
}
.white {
  background-color: #ffffff;
}
.border-top {
  border-top: 1px solid #dedef5 !important;
}
.logo {
  margin-left: 100px;
  display: flex;
  align-items: center;
}
.macwk-footer .logo img {
  width: 32px;
  margin-right: 15px;
}
.macwk-footer .logo span {
  font-size: 24px;
  font-weight: 700;
  flex-grow: 1;
  color: #000000;
}
.macwk-footer > .container,
.macwk-footer > .container-fluid,
.macwk-footer > .container-lg,
.macwk-footer > .container-md,
.macwk-footer > .container-sm,
.macwk-footer > .container-xl,
.macwk-footer > .container-xxl {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  height: inherit;
}
.stop-color-circle {
  stop-color: rgb(0, 0, 0);
}
.stop-color-default-linearGradient {
  stop-color: #fff;
}
.mb-0,
.my-0 {
  margin-bottom: 0 !important;
}
.ml-4 {
  margin-left: 1rem !important;
}
.nav-dev {
  display: flex;
  flex-wrap: wrap;
  padding-left: 0;
  margin-bottom: 0;
  list-style: none;
}
.nav-link {
  display: block;
  color: #414141;
  padding: 0.5rem 1rem;
}
.nav-link:focus,
.nav-link:hover {
  text-decoration: none;
  color: rgb(97, 157, 236);
}
.nav-link.disabled {
  color: #000000;
  pointer-events: none;
  cursor: default;
}
.nav-pills .nav-link {
  border-radius: 0.125rem;
}
.nav-pills .nav-link.active,
.nav-pills .show > .nav-link {
  color: #000000;
  background-color: #000000;
}
.nav-fill .nav-item {
  flex: 1 1 auto;
  text-align: center;
}
.nav-justified .nav-item {
  flex-basis: 0;
  flex-grow: 1;
  text-align: center;
}
.copyright {
  margin-right: 50px;
}
.mr-3 a {
  color: #000000;
}
</style>
